package org.teremail.server;

import org.teremail.client.FolderController;
import org.teremail.client.MailServiceAsync;
import org.teremail.client.MessageSummary;

import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;

public class GwtTestFolderController extends GWTTestCase {

    public String getModuleName() {
        return "org.teremail.TestTereMailClient";
    }
    
    public void testCreate() {
        FlexTable ft = new FlexTable();
        final String mailboxName = "homer";
        final String[] folders = { "INBOX", "Drafts", "Sent", "Trash" };
        final boolean[] called = { false };
        
        FolderController fc = new FolderController(ft, VerificationHelper.mockErrorHandler, 
                new MailServiceAsync() {
                    public void getFolders(String mailbox, AsyncCallback<String[]> callback) {
                        assertEquals(mailboxName, mailbox);
                        callback.onSuccess(folders);
                        called[0] = true;
                    }

                    public void getMessage(String mailbox, String folder, int uid,
                                           AsyncCallback<String> asyncCallback) {
                        fail();
                    }

                    public void getMessageSummaries(String mailbox, String folder, 
                                                    AsyncCallback<MessageSummary[]> asyncCallback) {
                        fail();
                    }
                });
        fc.fetchFolders(mailboxName);
        assertEquals(5, ft.getRowCount());
        assertTrue("Hasn't called service", called[0]);
    }

}
